const int MAX_SIZE = 1024;
class MinStack {

public:
    MinStack() { topIndex = -1; }

    void push(int val) {
        if (topIndex >= MAX_SIZE - 1) {
            cout << "stack overflow" << endl;
            return;
        }
        mainStack[++topIndex] = val;
        if (topIndex == 0 || minStack[topIndex - 1] > val) {
            minStack[topIndex] = val;
        } else {
            minStack[topIndex] = minStack[topIndex - 1];
        }
    }

    void pop() {
        if (topIndex < 0) {
            cout << "stack underflow" << endl;
            return;
        }
        --topIndex;
    }

    int top() {
        if (topIndex >= 0)
            return mainStack[topIndex];
        else
            return INT_MIN;
    }

    int getMin() {
        if (topIndex >= 0)
            return minStack[topIndex];
        else
            return INT_MIN;
    }

private:
    int mainStack[MAX_SIZE];
    int minStack[MAX_SIZE];
    int topIndex;
};

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack* obj = new MinStack();
 * obj->push(val);
 * obj->pop();
 * int param_3 = obj->top();
 * int param_4 = obj->getMin();
 */
 